package com.audaque.springboot.foshanupload.core.util.ssl.model;


import javax.net.ssl.*;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.function.Predicate;

public class AnyTrustManager implements X509TrustManager {
    private Predicate<X509Certificate> predicate;

    public AnyTrustManager(Predicate<X509Certificate> predicate) {
        this.predicate = predicate;
    }

    public X509Certificate[] getAcceptedIssuers() {
        return null;
    }

    public void checkServerTrusted(X509Certificate[] x509Certificate, String authType) throws CertificateException {
        if (x509Certificate != null && this.predicate != null) {
            X509Certificate[] var3 = x509Certificate;
            int var4 = x509Certificate.length;

            for (int var5 = 0; var5< var4;++var5){
                X509Certificate c = var3[var5];
                if (!this.predicate.test(c)) {
                    throw new CertificateException();
                }
            }
        }

    }

    public void checkClientTrusted(X509Certificate[] x509Certificate, String authType) throws CertificateException {
        if (x509Certificate != null && this.predicate != null) {
            X509Certificate[] var3 = x509Certificate;
            int var4 = x509Certificate.length;

            for (int var5 = 0; var5< var4; ++var5){
                X509Certificate c = var3[var5];
                if (!this.predicate.test(c)) {
                    throw new CertificateException();
                }
            }
        }

    }
}
